﻿using System;
using System.Configuration;
using System.Web.Configuration;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Data;

/// <summary>
///class  SqlBooksProvider 
///  Provides access to SqlServer data source
/// </summary>
public class Emails
{
    private static bool _isInitialized = false;
    private static EmailProvider _provider;
    private static SmallBusinessDataProvidersSection _providersSection;

    public static EmailProvider Provider
    {
        get
        {
            Initialize();
            return _provider;
        }
    }

    public static List<Email> GetAllEmails()
    {
        return Provider.GetAllEmails();
    }


    private static void Initialize()
    {
        if (!_isInitialized)
        {
            _providersSection = (ConfigurationManager.GetSection("SmallBusinessDataProviders")) as SmallBusinessDataProvidersSection;
            if (_providersSection == null)
            {
                throw new Exception(Messages.EmailConfigSectionNotFound);
            }

            _provider = ProvidersHelper.InstantiateProvider(_providersSection.EmailProviders[_providersSection.EmailProviderName],
                typeof(EmailProvider)) as EmailProvider;

            if (_provider == null)
            {
                throw new Exception("email default provider could not be instantiated");
            }
        }
    }
}
